package com.heifeng.cloudshelf.utils;

import android.content.Context;
import android.content.Intent;

import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.constants.HTTPConstants;
import com.heifeng.cloudshelf.mvp.main.activity.MainActivity;
import com.heifeng.cloudshelf.network.NetClient;
import com.heifeng.cloudshelf.widget.AppDialog;
import com.orhanobut.hawk.Hawk;

public class LoginErrorUtils {

    public static void loginOut(Context _context, int code, String message) {
        if (600001 == code) {
            clean();
            ShowTimeOverDialog(_context, message);
//            _context.startActivity(new Intent(_context, MainActivity.class));
        } else if (210819 == code) {
            clean();
            _context.startActivity(new Intent(_context, MainActivity.class));
        }
    }

    private static void clean() {
        NetClient.cliId = "";
        NetClient.token = "";
        HTTPConstants.userId = "";
        HTTPConstants.isLogined = false;
        Hawk.delete(HTTPConstants.USER_ID_KEY);
        Hawk.delete(HTTPConstants.TOKEN_KEY);
        Hawk.delete(HTTPConstants.CLIID_KEY);
    }

    public static void ShowTimeOverDialog(Context mContext, String message) {//到期提示dialog
        AppDialog.OneButtonDialog(mContext, mContext.getResources().getString(R.string.text_time_over_tips), message,
                mContext.getResources().getString(R.string.text_i_know), new AppDialog.OneButtonOnClickListener() {
                    @Override
                    public void onBtnClick() {
                        //ToastUitl.showLong("到期提示");
                        //ShowLoginDialog();
                        mContext.startActivity(new Intent(mContext, MainActivity.class));
                    }
                }).showDialog();
    }


}
